package model.keyboard 
{
	import controller.IGameController;
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	/**
	 * ...
	 * @author Yang Wang
	 */
	public class ControllBinder 
	{
		private var m_controller:IGameController;
		private var m_stage:Stage;
		private var m_keyMap:KeyMap;
		
		public function ControllBinder(gameController:IGameController, stage:Stage) 
		{
			m_controller = gameController;
			m_stage = stage;
			m_keyMap = new KeyMap();
		}
		
		public function bind() : void {
			m_stage.addEventListener(KeyboardEvent.KEY_DOWN, applyKeyDownMapping);
		}
		
		public function applyKeyDownMapping(e:KeyboardEvent) : void {
			switch(e.keyCode) {
				case m_keyMap.LeftKey:
					m_controller.moveLeft();
					break;
				case m_keyMap.RightKey:
					m_controller.moveRight();
					break;
				case m_keyMap.RotateLeftKey:
					m_controller.rotateLeft();
					break;
				case m_keyMap.RotateRightKey:
					m_controller.rotateRight();
					break;
				case m_keyMap.SoftDropKey:
					m_controller.softDrop();
					break;
				case m_keyMap.HardDropKey:
					m_controller.hardDrop();
					break;
				case m_keyMap.PauseKey:
					m_controller.pause();
				case m_keyMap.HoldKey:
					m_controller.hold();
					break;
			}
		}
		
	}

}